package com.fengye.algorithms.leecode.dp;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Author fengye
 * @Date 2023/4/8 11:24
 **/
public class YanhuiMain118 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int num = in.nextInt();
            if(num == 1) {
                System.out.println("[[1]]");
                continue;
            }

            List<List<Integer>> d = generate(num);
            int[][] dp = new int[num][num];

            for (int i=0;i<num;i++) {
                for(int j=0;j<=i;j++) {
                    if(j==0 || j == i) {
                        dp[i][j] = 1;
                        continue;
                    }
                    dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
                }
            }
            StringBuilder builder = new StringBuilder();
            builder.append("[");
            for(int i=0;i<num;i++) {
                builder.append("[");
                for (int j = 0; j <= i; j++) {
                    builder.append(dp[i][j]);
                    if(j < i) {
                        builder.append(",");
                    }
                }
                builder.append("]");
                if((i+1) < num) {
                    builder.append(",");
                }
            }
            builder.append("]");
            System.out.println(builder.toString());
        }
    }

    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> dp = new ArrayList<List<Integer>>(numRows);
        for(int i=0;i<numRows;i++) {
            List<Integer> adp = new ArrayList<Integer>(numRows);
            dp.add(i, adp);
            for(int j=0;j<=i;j++) {
                if(j==0 || j == i) {
                    adp.add(j,1);
                    continue;
                }
                List<Integer> tadp = dp.get(i-1);
                adp.add(j, tadp.get(j - 1) + tadp.get(j));
            }
        }
        return dp;
    }
}
